<?php
/**
 * 后台角色表
 *
 * @author     mole<mole1230@gmail.com>
 * @version    $Id: AdminRole.php 85 2011-01-07 08:40:13Z mole1230 $
 *
 * @property integer $id
 * @property string $honor
 * @property string $acls
 */
class AdminRole extends CActiveRecord
{
	const SUPER_RANK_ID = 127;
	const MAX_RANK_ID = 128;
	
	/**
	 * Returns the static model of the specified AR class.
	 * 
	 * @return AdminRole the static model class
	 */
	public static function model($className = __CLASS__)
	{
		return parent::model($className);
	}
	
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{admin_role}}';
	}
	
	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('id, honor', 'required'), 
			array('id', 'numerical', 'integerOnly' => true), 
			array('honor', 'length', 'max' => 15),
		);
	}
	
	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array();
	}
	
	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => '角色ID', 
			'honor' => '头衔', 
			'acls' => '权限'
		);
	}
	
	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * 
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search($rank, $limit = 20)
	{
		$criteria = new CDbCriteria();
		$criteria->compare('id', " < {$rank}");
		$criteria->order = 'id DESC';
		
		return new CActiveDataProvider(get_class($this), 
			array(
				'criteria' => $criteria,
				'pagination' => array(
					'pageSize' => $limit
				)
			));
	}
}
